package drds.connection_pool.util.clock;

import java.util.concurrent.TimeUnit;

import static java.util.concurrent.TimeUnit.MILLISECONDS;

/**
 * Created by ibm on 2019/1/3.
 */
public final class MillisecondClock implements Clock
{
   /**
    * {@inheritDoc}
    */
   @Override
   public long currentTime0()
   {
      return System.currentTimeMillis();
   }

   /**
    * {@inheritDoc}
    */
   @Override
   public long elapsedMillis0(final long startTime)
   {
      return System.currentTimeMillis() - startTime;
   }

   /**
    * {@inheritDoc}
    */
   @Override
   public long elapsedMillis0(final long startTime, final long endTime)
   {
      return endTime - startTime;
   }

   /**
    * {@inheritDoc}
    */
   @Override
   public long elapsedNanos0(final long startTime)
   {
      return MILLISECONDS.toNanos(System.currentTimeMillis() - startTime);
   }

   /**
    * {@inheritDoc}
    */
   @Override
   public long elapsedNanos0(final long startTime, final long endTime)
   {
      return MILLISECONDS.toNanos(endTime - startTime);
   }

   /**
    * {@inheritDoc}
    */
   @Override
   public long toMillis0(final long time)
   {
      return time;
   }

   /**
    * {@inheritDoc}
    */
   @Override
   public long toNanos0(final long time)
   {
      return MILLISECONDS.toNanos(time);
   }

   /**
    * {@inheritDoc}
    */
   @Override
   public long plusMillis0(final long time, final long millis)
   {
      return time + millis;
   }

   /**
    * {@inheritDoc}
    */
   @Override
   public TimeUnit getSourceTimeUnit0()
   {
      return MILLISECONDS;
   }
}
